<?php
class Default_Model_TableColumn_PtrTinRao {
	const DATE_FORMAT_FULL_EN = 'Y-m-d H:i:s';
	const DATE_FORMAT_FULL_VN = 'd/m/Y H:i:s';
	const DATE_FORMAT_SHORT_VN = 'd-m-Y';
	protected $id;
	protected $tieu_de;
	protected $mo_ta;
	protected $loai_tin;
	protected $dia_chi;
	protected $video_url;
	protected $hinh_anh;
	protected $thanh_pho;
	protected $quan_huyen;
	protected $goi_tin;
	protected $loai_phong;
	protected $so_nguoi_o;
	protected $dien_tich;
	protected $gia_phong;
	protected $gia_dien;
	protected $gia_nuoc;
	protected $nguoi_lien_he;
	protected $so_dien_thoai;
	protected $con_phong;
	protected $luot_xem;
	protected $latitude;
	protected $longitude;
	protected $ngay_dang;
	protected $hien_thi;
	protected $nguoi_dang;
	protected $trang_thai;
	protected $ngay_bat_dau;
	protected $ngay_het_han;


	public function __construct(array $options = null) {
		if (is_array($options)) {
			$this->setOptions($options);
		}
	}
	
	public function __set($name, $value) {
		$method = 'set' . $name;
		if (('mapper' == $name) || !method_exists($this, $method)) {
			throw new Exception('Invalid content property');
		}
		$this->$method($value);
	}
	
	public function __get($name) {
		$method = 'get' . $name;
		if (('mapper' == $name) || !method_exists($this, $method)) {
			throw new Exception('Invalid content property');
		}
		return $this->$method();
	}
	
	public function setOptions(array $options) {
		$methods = get_class_methods($this);
		foreach ($options as $key => $value) {
			$method = 'set' . ucfirst($key);
			if (in_array($method, $methods)) {
				$this->$method($value);
			}
		}
		return $this;
	}
	
	//id
	public function getId() {
		return $this->id;
	}
	
	public function setId($id) {
		$this->id = $id;
	}
	
	//tieu_de
	public function getTieu_de() {
		return $this->tieu_de;
	}
	
	public function setTieu_de($tieu_de) {
		$this->tieu_de = $tieu_de;
	}
	
	//mo_ta
	public function getMo_ta() {
		return $this->mo_ta;
	}
	
	public function setMo_ta($mo_ta) {
		$this->mo_ta = $mo_ta;
	}
	
	//loai_tin
	public function getLoai_tin() {
		return $this->loai_tin;
	}
	
	public function setLoai_tin($loai_tin) {
		$this->loai_tin = $loai_tin;
	}
	
	//dia_chi
	public function getDia_chi() {
		return $this->dia_chi;
	}
	
	public function setDia_chi($dia_chi) {
		$this->dia_chi = $dia_chi;
	}
	
	//video_url
	public function getVideo_url() {
		return $this->video_url;
	}
	
	public function setVideo_url($video_url) {
		$this->video_url = $video_url;
	}
	
	//hinh_anh
	public function getHinh_anh() {
		return $this->hinh_anh;
	}
	
	public function setHinh_anh($hinh_anh) {
		$this->hinh_anh = $hinh_anh;
	}
	
	//quan_huyen
	public function getQuan_huyen() {
		return $this->quan_huyen;
	}
	
	public function setQuan_huyen($quan_huyen) {
		$this->quan_huyen = $quan_huyen;
	}
	
	//thanh_pho
	public function getThanh_pho() {
		return $this->thanh_pho;
	}
	public function setThanh_pho($thanh_pho) {
		$this->thanh_pho = $thanh_pho;
	}
	
	//goi_tin
	public function getGoi_tin() {
		return $this->goi_tin;
	}
	
	public function setGoi_tin($goi_tin) {
		$this->goi_tin = $goi_tin;
	}
	
	//loai_phong
	public function getLoai_phong() {
		return $this->loai_phong;
	}
	
	public function setLoai_phong($loai_phong) {
		$this->loai_phong = $loai_phong;
	}
	
	//so_nguoi_o
	public function getSo_nguoi_o() {
		return $this->so_nguoi_o;
	}
	
	public function setSo_nguoi_o($so_nguoi_o) {
		$this->so_nguoi_o = $so_nguoi_o;
	}
	
	//dien_tich
	public function getDien_tich() {
		return $this->dien_tich;
	}
	
	public function setDien_tich($dien_tich) {
		$this->dien_tich = $dien_tich;
	}
	
	//gia_phong
	public function getGia_phong() {
		return $this->gia_phong;
	}
	
	public function setGia_phong($gia_phong) {
		$this->gia_phong = $gia_phong;
	}
	
	//gia_dien
	public function getGia_dien() {
		return $this->gia_dien;
	}
	
	public function setGia_dien($gia_dien) {
		$this->gia_dien = $gia_dien;
	}
	
	//gia_nuoc
	public function getGia_nuoc() {
		return $this->gia_nuoc;
	}
	
	public function setGia_nuoc($gia_nuoc) {
		$this->gia_nuoc = $gia_nuoc;
	}
	
	//nguoi_lien_he
	public function getNguoi_lien_he() {
		return $this->nguoi_lien_he;
	}
	
	public function setNguoi_lien_he($nguoi_lien_he) {
		$this->nguoi_lien_he = $nguoi_lien_he;
	}
	
	//so_dien_thoai
	public function getSo_dien_thoai() {
		return $this->so_dien_thoai;
	}
	
	public function setSo_dien_thoai($so_dien_thoai) {
		$this->so_dien_thoai = $so_dien_thoai;
	}
	
	//con_phong
	public function getCon_phong() {
		return $this->con_phong;
	}
	
	public function setCon_phong($con_phong) {
		$this->con_phong = $con_phong;
	}
	
	//luot_xem
	public function getLuot_xem() {
		return $this->luot_xem;
	}
	
	public function setLuot_xem($luot_xem) {
		$this->luot_xem = $luot_xem;
	}
	
	//latitude
	public function getLatitude() {
		return $this->latitude;
	}
	
	public function setLatitude($latitude) {
		$this->latitude = $latitude;
	}
	
	//longitude
	public function getLongitude() {
		return $this->longitude;
	}
	
	public function setLongitude($longitude) {
		$this->longitude = $longitude;
	}
	
	//ngay_dang
	public function getNgay_dang($format = self::DATE_FORMAT_FULL_VN) {
		return date($format,strtotime($this->ngay_dang));
	}
	
	public function setNgay_dang($value) {
		$this->ngay_dang = date(self::DATE_FORMAT_FULL_EN, strtotime($value));
	}
	
	//hien_thi
	public function getHien_thi() {
		return $this->hien_thi;
	}
	
	public function setHien_thi($hien_thi) {
		$this->hien_thi = $hien_thi;
	}
	
	//nguoi_dang
	public function getNguoi_dang() {
		return $this->nguoi_dang;
	}
	
	public function setNguoi_dang($nguoi_dang) {
		$this->nguoi_dang = $nguoi_dang;
	}
	
	//trang_thai
	public function getTrang_thai() {
		return $this->trang_thai;
	}
	
	public function setTrang_thai($trang_thai) {
		$this->trang_thai = $trang_thai;
	}
	
	//ngay_bat_dau_hien_thi
	public function getNgay_bat_dau_hien_thi($format = self::DATE_FORMAT_FULL_EN) {
		return date($format, strtotime($this->ngay_bat_dau));
	}
	
	public function setNgay_bat_dau_hien_thi($value) {
		$this->ngay_bat_dau = date(self::DATE_FORMAT_FULL_EN, strtotime($value));
	}
	
	//ngay_het_han
	public function getNgay_het_han($format = self::DATE_FORMAT_FULL_EN) {
		return date($format, strtotime($this->ngay_het_han));
	}
	
	public function setNgay_het_han($value) {
		$this->ngay_het_han = date(self::DATE_FORMAT_FULL_EN, strtotime($value));
	}
	
	//Get reference
	//loai tin
	public function getLoaiTinObj() {
		$loaitin = new Default_Model_LoaiTinMapper();
		if($this->getLoai_tin() != null){
			foreach ($loaitin->fetchAll('id = ' . $this->getLoai_tin()) as $loai_tin_obj)
			return $loai_tin_obj;
		}
	}
	
	//goi tin
	public function getGoiTinObj() {
		$goitin = new Default_Model_GoiTinMapper();
		if($this->getGoi_tin() != null){
			foreach ($goitin->fetchAll('id = ' . $this->getGoi_tin()) as $goi_tin_obj)
			return $goi_tin_obj;
		}
	}
	
	//loai phong
	public function getLoaiPhongObj() {
		$loaiphong = new Default_Model_LoaiPhongMapper();
		if($this->getLoai_phong() != null){
			foreach ($loaiphong->fetchAll('id = ' . $this->getLoai_phong()) as $loai_phong_obj)
			return $loai_phong_obj;
		}
	}
	
	//quan huyen
	public function getQuanHuyenObj() {
		$quanhuyen = new Default_Model_QuanHuyenMapper();
		if($this->getQuan_huyen() != null) {
			foreach ($quanhuyen->fetchAll('id = ' . $this->getQuan_huyen()) as $quan_huyen_obj)
				return $quan_huyen_obj;
		}
	}
	
	//thanh pho
	public function getThanhPhoObj() {
		$thanhpho = new Admin_Model_ThanhPhoMapper();
		if($this->getThanh_pho() != null){
			foreach ($thanhpho->fetchAll('id = '. $this->getThanh_pho(), 'view') as $thanhphoobj)
			return $thanhphoobj;
		}
	}

	//nguoi tao
	public function getNguoiDangObj() {
		$user = new Default_Model_UsersMapper();
		if($this->getNguoi_dang() != null){
        	$user_obj = $user->fetchAll('id='. $this->getNguoi_dang(), 'view');
			return $user_obj;
		}
	}
	
	//nguoi duyet
	public function getNguoiDuyetObj() {
		$useradmin = new Default_Model_UsersAdminMapper();
		if($this->getNguoi_duyet() != null) {
			foreach ($useradmin->fetchAll('id = ' . $this->getNguoi_duyet()) as $user_obj)
			return $user_obj;
		}
	}
	
	// trang thai
	public function getTrangThaiStr() {
		switch ($this->trang_thai) {
			case 0: return "Chưa duyệt";
			case 1: return "Đã duyệt";
			case 2: return "Yêu cầu thay đổi";
			case 3: return "Không hợp lệ";
			default:  return "";
		}
	}

	//to array
	public function toArray() {
		$data= array(
			'id'			=> $this->id,
			'tieu_de'		=> $this->tieu_de,
			'mo_ta'			=> $this->mo_ta,
			'loai_tin' 		=> $this->loai_tin,
			'dia_chi' 		=> $this->dia_chi,
			'video_url'		=> $this->video_url,
			'hinh_anh'		=> $this->hinh_anh,
			'quan_huyen'	=> $this->quan_huyen,
			'thanh_pho'		=> $this->thanh_pho,
			'goi_tin'		=> $this->goi_tin,
			'loai_phong'	=> $this->loai_phong,
			'so_nguoi_o'	=> $this->so_nguoi_o,
			'dien_tich'		=> $this->dien_tich,
			'gia_phong'		=> $this->gia_phong,
			'nguoi_lien_he'	=> $this->nguoi_lien_he,
			'so_dien_thoai'	=> $this->so_dien_thoai,
			'luot_xem'		=> $this->luot_xem,
			'latitude'		=> $this->latitude,
			'longitude'		=> $this->longitude,
			'ngay_dang'		=> $this->ngay_dang,
			'nguoi_dang'	=> $this->nguoi_dang,
			'trang_thai'	=> $this->trang_thai,
			'ngay_bat_dau'	=> $this->ngay_bat_dau,
			'ngay_het_han'	=> $this->ngay_het_han,
		);
		$item = array();
		foreach ($data as $key =>$value) {
			if ($value!=''&& $value!=null) {
				$item[$key]=$value;
			}
		}
		return $item;
	}
}